// Created by WXX on 2021/12/24 19:31
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>

using namespace std;

/**
 * 执行用时：0 ms, 在所有 C++ 提交中击败了100.00%的用户
 * 内存消耗：6.6 MB, 在所有 C++ 提交中击败了12.44%的用户
 */
class Solution {
public:
    vector<string> findOcurrences(string text, string first, string second) {
        stringstream ssin(text);
        vector<string> strs;
        string str;
        while (ssin >> str) strs.push_back(str);

        vector<string> res;
        for (int i = 0; i + 2 < strs.size(); i++) {
            if (strs[i] == first && strs[i + 1] == second)
                res.push_back(strs[i + 2]);
        }
        return res;
    }
};

void OutputBasicArray1D(vector<string> nums) {
    cout << "[";
    for (int i = 0; i < nums.size(); i++) {
        cout << nums[i];
        if (i != nums.size() - 1) cout << ", ";
    }
    cout << "]" << endl;
}

int main() {

    string text = "alice is a good girl she is a good student", first = "a", second = "good";
    OutputBasicArray1D(Solution().findOcurrences(text, first, second));

    return 0;
}
